using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;

namespace PortalCurriculo.Util.Encryption
{
   internal class DecryptTransformer
   {
       internal DecryptTransformer(EncryptTransformer.EncryptionAlgorithm deCryptId) 
      { 
        algorithmID = deCryptId; 
      }

      private EncryptTransformer.EncryptionAlgorithm algorithmID; 
      private byte[] initVec; 

      internal ICryptoTransform GetCryptoServiceProvider(byte[] bytesKey) 
      { 
        // Pick the provider. 
        switch (algorithmID) 
        {
         case EncryptTransformer.EncryptionAlgorithm.Des: 
          { 
            DES des = new DESCryptoServiceProvider(); 
            des.Mode = CipherMode.CBC; 
            des.Key = bytesKey; 
            des.IV = initVec; 
            return des.CreateDecryptor(); 
          }
         case EncryptTransformer.EncryptionAlgorithm.TripleDes: 
          { 
            TripleDES des3 = new TripleDESCryptoServiceProvider(); 
            des3.Mode = CipherMode.CBC; 
            return des3.CreateDecryptor(bytesKey, initVec); 
          }
         case EncryptTransformer.EncryptionAlgorithm.Rc2: 
          {  
            RC2 rc2 = new RC2CryptoServiceProvider(); 
            rc2.Mode = CipherMode.CBC; 
            return rc2.CreateDecryptor(bytesKey, initVec); 
          }
         case EncryptTransformer.EncryptionAlgorithm.Rijndael: 
          { 
            Rijndael rijndael = new RijndaelManaged(); 
            rijndael.Mode = CipherMode.CBC; 
            return rijndael.CreateDecryptor(bytesKey, initVec); 
          }  
          default: 
          { 
            throw new CryptographicException("Algorithm ID '" + algorithmID +  
                                             "' not supported."); 
          } 
        } 
      } //end GetCryptoServiceProvider 

      internal byte[] IV 
      { 
        set{initVec = value;} 
      } 
   }
}
